package com.zegome.game.gomestory.main.helper;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable;

public class AnimationDrawable extends BaseDrawable
{
	public TextureRegion[] regions;
	
	boolean isLoop, isStop;
	
	float tick;
	float[] fps;
	int frame;	
	float x,y,wi,hi;
	
	public void setRegions(TextureRegion[] regions){
		this.regions = regions;
	}
	
	public AnimationDrawable(TextureRegion[] regions,float x, float y, float wi, float hi, float[] fps, boolean isLoop)
	{
		this.regions = regions;
		this.isLoop = isLoop;
		this.fps = fps;	
		this.wi = wi;
		this.hi = hi;
		this.x = x;
		this.y = y;
	}
	
public void act(float delta)
{
	if(isStop == false){
		if(tick>=fps[frame]){
			tick = 0;
			frame ++;
			if(frame==regions.length){				
				if(isLoop){
					frame = 0;
				}
				else{
				frame = regions.length-1;
				isStop = true;
				}
			}
		}
		else{
			tick+=delta;
		}
		
		}
}

public void reset()
{
	isStop = false;
	frame = 0;
	tick = 0;
}

@Override
public void draw(SpriteBatch batch, float x, float y, float width, float height)
{
	batch.draw(regions[frame], this.x, this.y, this.wi, this.hi);
}
}